import { CSSProperties } from "vue";
import { useNavTabs } from "../store/navTabs";
import { useConfig } from "../store/config";
import router from "../router/index";
// import { isAdminApp } from "/@/utils/common";

/**
 * main高度
 * @param extra main高度额外减去的px数,可以实现隐藏原有的滚动条
 * @returns CSSProperties
 */
export function mainHeight(extra = 0): CSSProperties {
  let height = extra;
  const adminLayoutMainExtraHeight: any = {
    Default: 70,
    Classic: 50,
    Streamline: 60,
  };
  if (isAdminAppOther()) {
    const config = useConfig();
    const navTabs = useNavTabs();
    //判断navTabs.state.tabFullScreen 当前tab是否全屏
    if (!navTabs.state.tabFullScreen) {
      //config.layout.layoutMode 后台布局方式，可选值<Default|Classic|Streamline>
      height += adminLayoutMainExtraHeight[config.layout.layoutMode];
    }
  } else {
    height += 60;
  }
  return {
    height: "calc(100vh - " + height.toString() + "px)",
  };
}

/**
 * 是否在后台/admin应用内
 */
export const isAdminAppOther = () => {
  //匹配以/admin开头的路由
  //router.currentRoute.value 匹配的组件可以从 router.currentRoute.value.matched 中获取
  if (
    /^\/admin/.test(router.currentRoute.value.fullPath) ||
    window.location.hash.indexOf("#/admin") === 0
  ) {
    return true;
  }
  return false;
};
